package com.college.heyuhua.dao;

import com.college.heyuhua.entity.Newsinfo;
import com.college.heyuhua.model.Newstyle;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by 赵东坡 on 2018/12/31.
 * Time:13:37
 * 宇宙无敌赵牛逼，祈求永无bug
 */
@Mapper
@Component
public interface NewMapper {


    @Select("<script>" +
            "select c.*\n" +
            "from (select *\n" +
            "from newsinfo\n" +
            "order by newsdate desc\n" +
            "limit 100) c\n" +
            "order by c.ctrcount\n" +
            "</script>")
    List<Newsinfo> homepagefour();



    @Select("<script>" +
            "select * " +
            "from newsinfo n " +
            "where n.nid = #{nid} " +
            "</script>")
    Newsinfo getOneMessage(@Param("nid") Long nid);


    @Select("<script>" +
            "select c.*\n" +
            "from (select *\n" +
            "      from newsinfo\n" +
            "      where newsstyleid = #{newsstyleid}\n" +
            "      order by newsdate desc\n" +
            "      limit 100) c\n" +
            "order by c.ctrcount" +
            "</script>")
    List<Newsinfo> getNewsBynewsstyleid(@Param("newsstyleid") int newsstyleid);


    @Delete("<script>" +
            "delete from newstyle where nsid = #{nsid}" +
            "</script>")
    boolean deletestyle(@Param("nsid") String nsid);


    @Select("<script>" +
            "select * " +
            "from newstyle " +
            "</script>")
    List<Newstyle> getstylenews();


    @Insert("<script>" +
            "insert into newstyle(stylename) values(#{stylename}) " +
            "</script>")
    boolean addstyle(@Param("stylename") String stylename);


    @Insert("<script>" +
            "insert into newsinfo(ntitle,ncontent,newsstyleid) values(#{ntitle},#{ncontent},#{newsstyleid}) " +
            "</script>")
    boolean addnewsinfo(@Param("ntitle")String ntitle,@Param("ncontent")String ncontent,@Param("newsstyleid")String newsstyleid);
}
